package com.weixing.mall.provider.controller.cms;

import com.weixing.mall.base.wrapper.Result;
import com.weixing.mall.base.wrapper.ResultUtil;
import com.weixing.mall.core.annotation.NoRepeatSubmit;
import com.weixing.mall.core.support.BaseController;
import com.weixing.mall.provider.model.dto.cms.AppVersionDto;
import com.weixing.mall.provider.model.query.AppVersionQuery;
import com.weixing.mall.provider.service.IAppVersionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName AppVersionController
 * @Description TODO <br/>
 * @Author gjq
 * @Modified By:
 * @Date 2019/7/25
 * @Version 1.0
 **/
@RestController
@RequestMapping("appVersion")
@Api(value = "app版本APi", tags = "app版本")
public class AppVersionController extends BaseController {

    @Autowired
    private IAppVersionService appVersionService;

    @ApiOperation(value = "加载app版本列表")
    @GetMapping("")
    public Result list(AppVersionQuery appVersionQuery) {
        return ResultUtil.success(appVersionService.selectOfPage(initMpPage(),appVersionQuery));
    }

    @ApiOperation(value = "保存app版本")
    @PostMapping("save")
    @NoRepeatSubmit
    public Result save(@Validated AppVersionDto appVersionDto) {
        appVersionService.save(appVersionDto);
        return  ResultUtil.success();
    }

    @ApiOperation(value = "发布app版本")
    @PostMapping("pubApp")
    @NoRepeatSubmit
    public Result pubApp(@Validated AppVersionDto appVersionDto) {
        appVersionService.pubApp(appVersionDto);
        return  ResultUtil.success();
    }

    @ApiOperation(value = "删除版本信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "app版本id", paramType = "path", dataType = "long")
    })
    @PostMapping("del/{id}")
    public Result del(@PathVariable long id) {
        return appVersionService.removeById(id)? ResultUtil.success() : ResultUtil.error();
    }


    @ApiOperation(value = "批量删除app版本")
    @DeleteMapping("delAll/{ids}")
    public Result delAll(@PathVariable int[] ids){
        appVersionService.deleteAll(ids);
        return ResultUtil.success();
    }


}
